<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox
        v-for="item in list"
        :key="item.id"
        :label="item.id"
      >{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="assignRoles">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getSetting } from '@/api/settings'
import { getUserByIdDetail } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    cerId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  created() {
    this.loadSetting()
  },
  methods: {
    // 发送请求给员工分配角色
    async assignRoles() {
      try {
        await assignRoles({ id: this.cerId, roleIds: this.roleIds })
        this.$emit('success')
      } catch (error) {
        console.log(error)
      }
    },
    // 发送请求，获得企业列表
    async  loadSetting() {
      try {
        const res = await getSetting({ page: 1, pagesize: 100 })
        // console.log(res)
        // 发送请求获得点击员工所对应的职务
        const detle = await getUserByIdDetail(this.cerId)
        console.log(detle)
        this.roleIds = detle.data.roleIds
        // const datle = await getUserByIdDetail()
        this.list = res.data.rows
        // console.log(this.list)
      } catch (error) {
        console.log(error)
      }
    },
    closeDialog() {

    }
  }
}
</script>
